def g(cr):
    k=0
    for i in range(2,cr//2+1):
        if cr%i==0:
            k=k+1
    if k>0:
        return(1)
    else:
        return(0)

def f(cr):
    k=0
    cr+=1
    while k==0:
        for i in range(2,cr//2+1):
            if cr%i==0:
                k=k+1
        if k==0:
            k=1
        else:
            cr+=1
            k=0
    return(cr)

def h(cr):
    k=0
    cr-=1
    while k==0:
        for i in range(2,cr//2+1):
            if cr%i==0:
                k=k+1
        if k==0:
            k=1
        else:
            cr-=1
            k=0
    return(cr)

s=['zero','one','two','three','four','five','six','seven','eight','nine']
d=['0','1','2','3','4','5','6','7','8','9']
p=input()
v=input()
t=input()
if p!='0' and p!='zero' and (p in s) and (v in s) and (t in s):
    p=s.index(p)
    v=s.index(v)
    t=s.index(t)
    cr=int(d[p]+d[v]+d[t])
else:
    print('Wrong input')
    import sys
    sys.exit()

cl1=g(cr)
cl2=f(cr)
cl3=h(cr)
if cl1==0:
    print(cr)
else:
        cl2=f(cr)
        cl3=h(cr)
        if (cl2-cr)<(cr-cl3):print(cl2)
        else:print(cl3)
